#include "thrifthandler.h"
#include "bcstmainthread.h"
#include <QMutexLocker>

QMutex ThriftHandler::g_mutex_flag1;
bool   ThriftHandler::g_flag1{false};

ThriftHandler::ThriftHandler(QObject *object):QObject (object) {
    // Your initialization goes here
}

int32_t
ThriftHandler::openRtBCST() {
    // Your implementation goes here
    printf("openRtBCST\n");
//    emit isOpenRtBCST();

//    QMutexLocker locker(&BcstMainThread::g_mutex_flag_openRtBCST);
    BcstMainThread::g_mutex_flag_openRtBCST.lock();
    BcstMainThread::g_flag_openRtBCST = true;
    BcstMainThread::g_mutex_flag_openRtBCST.unlock();

    while(ThriftHandler::g_flag1==false);
//    QMutexLocker locker(&ThriftHandler::g_mutex_flag1);
    ThriftHandler::g_mutex_flag1.lock();
    ThriftHandler::g_flag1 = false;
    ThriftHandler::g_mutex_flag1.unlock();
    qDebug()<<"openRtBCST() return";
    return 1;
}

int32_t
ThriftHandler:: closeRtBCST() {
    // Your implementation goes here
    printf("closeRtBCST\n");
//    emit isCloseRtBCST();

//    QMutexLocker locker(&BcstMainThread::g_mutex_flag1);
    BcstMainThread::g_mutex_flag_closeRtBCST.lock();
    BcstMainThread::g_flag_closeRtBCST = true;
    BcstMainThread::g_mutex_flag_closeRtBCST.unlock();

    while(ThriftHandler::g_flag1==false);
    ThriftHandler::g_mutex_flag1.lock();
    ThriftHandler::g_flag1 = false;
    ThriftHandler::g_mutex_flag1.unlock();
    qDebug()<<"closeRtBCST() return";
    return 1;
}

